package cn.edu.xmu.talk.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.xmu.cc.talk.TalkBeanRemote;
import cn.edu.xmu.cc.talk.entity.CCMessage;
import cn.edu.xmu.talk.utils.ContextManagerFactory;

public class GetMessageServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req,resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String userId = req.getParameter("userId");
		TalkBeanRemote bean = ContextManagerFactory.getSessionBean();
		List<CCMessage> messageList = bean.getMessage(Integer.parseInt(userId));
		resp.setCharacterEncoding("utf-8");
		for(int i = 0;i < messageList.size();++i){
			resp.getWriter().print(messageList.get(i));
		}
	}
	
}
